<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>MD5 xref</title>
<link type="text/css" rel="stylesheet" href="../../../../../stylesheet.css" />
</head>
<body>
<div id="overview"><a href="../../../../../../apidocs/com/totsp/gwittir/client/util/MD5.html">View Javadoc</a></div><pre>

<a name="1" href="#1">1</a>   <em class="jxr_comment">/*</em>
<a name="2" href="#2">2</a>   <em class="jxr_comment"> * $Header: /cvsroot/jwebmail/jwebmail-0.7/src/net/wastl/webmail/misc/MD5.java,v 1.1.1.1 2002/11/21 21:20:20 wastl Exp $</em>
<a name="3" href="#3">3</a>   <em class="jxr_comment"> *</em>
<a name="4" href="#4">4</a>   <em class="jxr_comment"> * MD5 in Java JDK Beta-2</em>
<a name="5" href="#5">5</a>   <em class="jxr_comment"> * written Santeri Paavolainen, Helsinki Finland 1996</em>
<a name="6" href="#6">6</a>   <em class="jxr_comment"> * (c) Santeri Paavolainen, Helsinki Finland 1996</em>
<a name="7" href="#7">7</a>   <em class="jxr_comment"> *</em>
<a name="8" href="#8">8</a>   <em class="jxr_comment"> * This library is free software; you can redistribute it and/or</em>
<a name="9" href="#9">9</a>   <em class="jxr_comment"> * modify it under the terms of the GNU Library General Public</em>
<a name="10" href="#10">10</a>  <em class="jxr_comment"> * License as published by the Free Software Foundation; either</em>
<a name="11" href="#11">11</a>  <em class="jxr_comment"> * version 2 of the License, or (at your option) any later version.</em>
<a name="12" href="#12">12</a>  <em class="jxr_comment"> *</em>
<a name="13" href="#13">13</a>  <em class="jxr_comment"> * This library is distributed in the hope that it will be useful,</em>
<a name="14" href="#14">14</a>  <em class="jxr_comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</em>
<a name="15" href="#15">15</a>  <em class="jxr_comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</em>
<a name="16" href="#16">16</a>  <em class="jxr_comment"> * Library General Public License for more details.</em>
<a name="17" href="#17">17</a>  <em class="jxr_comment"> *</em>
<a name="18" href="#18">18</a>  <em class="jxr_comment"> * You should have received a copy of the GNU Library General Public</em>
<a name="19" href="#19">19</a>  <em class="jxr_comment"> * License along with this library; if not, write to the Free</em>
<a name="20" href="#20">20</a>  <em class="jxr_comment"> * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</em>
<a name="21" href="#21">21</a>  <em class="jxr_comment"> *</em>
<a name="22" href="#22">22</a>  <em class="jxr_comment"> * See <a href="http://www.cs.hut.fi/~santtu/java/" target="alexandria_uri">http://www.cs.hut.fi/~santtu/java/</a> for more information on this</em>
<a name="23" href="#23">23</a>  <em class="jxr_comment"> * class.</em>
<a name="24" href="#24">24</a>  <em class="jxr_comment"> *</em>
<a name="25" href="#25">25</a>  <em class="jxr_comment"> * This is rather straight re-implementation of the reference implementation</em>
<a name="26" href="#26">26</a>  <em class="jxr_comment"> * given in RFC1321 by RSA.</em>
<a name="27" href="#27">27</a>  <em class="jxr_comment"> *</em>
<a name="28" href="#28">28</a>  <em class="jxr_comment"> * Passes MD5 test suite as defined in RFC1321.</em>
<a name="29" href="#29">29</a>  <em class="jxr_comment"> *</em>
<a name="30" href="#30">30</a>  <em class="jxr_comment"> *</em>
<a name="31" href="#31">31</a>  <em class="jxr_comment"> * This Java class has been derived from the RSA Data Security, Inc. MD5</em>
<a name="32" href="#32">32</a>  <em class="jxr_comment"> * Message-Digest Algorithm and its reference implementation.</em>
<a name="33" href="#33">33</a>  <em class="jxr_comment"> *</em>
<a name="34" href="#34">34</a>  <em class="jxr_comment"> *</em>
<a name="35" href="#35">35</a>  <em class="jxr_comment"> * $Log: MD5.java,v $</em>
<a name="36" href="#36">36</a>  <em class="jxr_comment"> * Revision 1.1.1.1  2002/11/21 21:20:20  wastl</em>
<a name="37" href="#37">37</a>  <em class="jxr_comment"> * Initial import.</em>
<a name="38" href="#38">38</a>  <em class="jxr_comment"> *</em>
<a name="39" href="#39">39</a>  <em class="jxr_comment"> * Revision 1.1.1.1  2002/10/02 18:42:49  wastl</em>
<a name="40" href="#40">40</a>  <em class="jxr_comment"> *</em>
<a name="41" href="#41">41</a>  <em class="jxr_comment"> *</em>
<a name="42" href="#42">42</a>  <em class="jxr_comment"> * Revision 1.1.1.1  2002/09/30 19:30:11  wastl</em>
<a name="43" href="#43">43</a>  <em class="jxr_comment"> *</em>
<a name="44" href="#44">44</a>  <em class="jxr_comment"> *</em>
<a name="45" href="#45">45</a>  <em class="jxr_comment"> * Revision 1.2  2001/11/18 16:42:20  wastl</em>
<a name="46" href="#46">46</a>  <em class="jxr_comment"> * *** empty log message ***</em>
<a name="47" href="#47">47</a>  <em class="jxr_comment"> *</em>
<a name="48" href="#48">48</a>  <em class="jxr_comment"> * Revision 1.1  2000/09/13 12:47:50  wastl</em>
<a name="49" href="#49">49</a>  <em class="jxr_comment"> * *** empty log message ***</em>
<a name="50" href="#50">50</a>  <em class="jxr_comment"> *</em>
<a name="51" href="#51">51</a>  <em class="jxr_comment"> * Revision 1.5  1996/12/12 10:47:02  santtu</em>
<a name="52" href="#52">52</a>  <em class="jxr_comment"> * Changed GPL to LGPL</em>
<a name="53" href="#53">53</a>  <em class="jxr_comment"> *</em>
<a name="54" href="#54">54</a>  <em class="jxr_comment"> * Revision 1.4  1996/12/12 10:30:02  santtu</em>
<a name="55" href="#55">55</a>  <em class="jxr_comment"> * Some typos, State -&gt; MD5State etc.</em>
<a name="56" href="#56">56</a>  <em class="jxr_comment"> *</em>
<a name="57" href="#57">57</a>  <em class="jxr_comment"> * Revision 1.3  1996/04/15 07:28:09  santtu</em>
<a name="58" href="#58">58</a>  <em class="jxr_comment"> * Added GPL statemets, and RSA derivate stametemetsnnts.</em>
<a name="59" href="#59">59</a>  <em class="jxr_comment"> *</em>
<a name="60" href="#60">60</a>  <em class="jxr_comment"> * Revision 1.2  1996/03/04 08:05:48  santtu</em>
<a name="61" href="#61">61</a>  <em class="jxr_comment"> * Added offsets to Update method</em>
<a name="62" href="#62">62</a>  <em class="jxr_comment"> *</em>
<a name="63" href="#63">63</a>  <em class="jxr_comment"> * Revision 1.1  1996/01/07 20:51:59  santtu</em>
<a name="64" href="#64">64</a>  <em class="jxr_comment"> * Initial revision</em>
<a name="65" href="#65">65</a>  <em class="jxr_comment"> *</em>
<a name="66" href="#66">66</a>  <em class="jxr_comment"> */</em>
<a name="67" href="#67">67</a>  <strong class="jxr_keyword">package</strong> com.totsp.gwittir.client.util;
<a name="68" href="#68">68</a>  
<a name="69" href="#69">69</a>  
<a name="70" href="#70">70</a>  <em class="jxr_javadoccomment">/**</em>
<a name="71" href="#71">71</a>  <em class="jxr_javadoccomment"> * Contains internal state of the MD5 class</em>
<a name="72" href="#72">72</a>  <em class="jxr_javadoccomment"> */</em>
<a name="73" href="#73">73</a>  
<a name="74" href="#74">74</a>  <strong class="jxr_keyword">class</strong> MD5State {
<a name="75" href="#75">75</a>    <em class="jxr_javadoccomment">/**</em>
<a name="76" href="#76">76</a>  <em class="jxr_javadoccomment">   * 128-byte state</em>
<a name="77" href="#77">77</a>  <em class="jxr_javadoccomment">   */</em>
<a name="78" href="#78">78</a>    <strong class="jxr_keyword">int</strong>	state[];
<a name="79" href="#79">79</a>  
<a name="80" href="#80">80</a>    <em class="jxr_javadoccomment">/**</em>
<a name="81" href="#81">81</a>  <em class="jxr_javadoccomment">   * 64-bit character count (could be true Java long?)</em>
<a name="82" href="#82">82</a>  <em class="jxr_javadoccomment">   */</em>
<a name="83" href="#83">83</a>    <strong class="jxr_keyword">int</strong>	count[];
<a name="84" href="#84">84</a>  
<a name="85" href="#85">85</a>    <em class="jxr_javadoccomment">/**</em>
<a name="86" href="#86">86</a>  <em class="jxr_javadoccomment">   * 64-byte buffer (512 bits) for storing to-be-hashed characters</em>
<a name="87" href="#87">87</a>  <em class="jxr_javadoccomment">   */</em>
<a name="88" href="#88">88</a>    byte	buffer[];
<a name="89" href="#89">89</a>  
<a name="90" href="#90">90</a>    <strong class="jxr_keyword">public</strong> MD5State() {
<a name="91" href="#91">91</a>      buffer = <strong class="jxr_keyword">new</strong> byte[64];
<a name="92" href="#92">92</a>      count = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">int</strong>[2];
<a name="93" href="#93">93</a>      state = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">int</strong>[4];
<a name="94" href="#94">94</a>  
<a name="95" href="#95">95</a>      state[0] = 0x67452301;
<a name="96" href="#96">96</a>      state[1] = 0xefcdab89;
<a name="97" href="#97">97</a>      state[2] = 0x98badcfe;
<a name="98" href="#98">98</a>      state[3] = 0x10325476;
<a name="99" href="#99">99</a>  
<a name="100" href="#100">100</a>     count[0] = count[1] = 0;
<a name="101" href="#101">101</a>   }
<a name="102" href="#102">102</a> 
<a name="103" href="#103">103</a>   <em class="jxr_javadoccomment">/**</em><em class="jxr_javadoccomment"> Create this State as a copy of another state */</em>
<a name="104" href="#104">104</a>   <strong class="jxr_keyword">public</strong> MD5State (MD5State from) {
<a name="105" href="#105">105</a>     <strong class="jxr_keyword">this</strong>();
<a name="106" href="#106">106</a> 
<a name="107" href="#107">107</a>     <strong class="jxr_keyword">int</strong> i;
<a name="108" href="#108">108</a> 
<a name="109" href="#109">109</a>     <strong class="jxr_keyword">for</strong> (i = 0; i &lt; buffer.length; i++)
<a name="110" href="#110">110</a>       <strong class="jxr_keyword">this</strong>.buffer[i] = from.buffer[i];
<a name="111" href="#111">111</a> 
<a name="112" href="#112">112</a>     <strong class="jxr_keyword">for</strong> (i = 0; i &lt; state.length; i++)
<a name="113" href="#113">113</a>       <strong class="jxr_keyword">this</strong>.state[i] = from.state[i];
<a name="114" href="#114">114</a> 
<a name="115" href="#115">115</a>     <strong class="jxr_keyword">for</strong> (i = 0; i &lt; count.length; i++)
<a name="116" href="#116">116</a>       <strong class="jxr_keyword">this</strong>.count[i] = from.count[i];
<a name="117" href="#117">117</a>   }
<a name="118" href="#118">118</a> }
<a name="119" href="#119">119</a> 
<a name="120" href="#120">120</a> <em class="jxr_javadoccomment">/**</em>
<a name="121" href="#121">121</a> <em class="jxr_javadoccomment"> * Implementation of RSA's MD5 hash generator</em>
<a name="122" href="#122">122</a> <em class="jxr_javadoccomment"> *</em>
<a name="123" href="#123">123</a> <em class="jxr_javadoccomment"> * @version	$Revision: 1.1.1.1 $</em>
<a name="124" href="#124">124</a> <em class="jxr_javadoccomment"> * @author	Santeri Paavolainen &lt;sjpaavol@cc.helsinki.fi&gt;</em>
<a name="125" href="#125">125</a> <em class="jxr_javadoccomment"> */</em>
<a name="126" href="#126">126</a> 
<a name="127" href="#127">127</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">class</strong> MD5 {
<a name="128" href="#128">128</a>   <em class="jxr_javadoccomment">/**</em>
<a name="129" href="#129">129</a> <em class="jxr_javadoccomment">   * MD5 state</em>
<a name="130" href="#130">130</a> <em class="jxr_javadoccomment">   */</em>
<a name="131" href="#131">131</a>   MD5State	state;
<a name="132" href="#132">132</a> 
<a name="133" href="#133">133</a>   <em class="jxr_javadoccomment">/**</em>
<a name="134" href="#134">134</a> <em class="jxr_javadoccomment">   * If Final() has been called, finals is set to the current finals</em>
<a name="135" href="#135">135</a> <em class="jxr_javadoccomment">   * state. Any Update() causes this to be set to null.</em>
<a name="136" href="#136">136</a> <em class="jxr_javadoccomment">   */</em>
<a name="137" href="#137">137</a>   MD5State 	finals;
<a name="138" href="#138">138</a> 
<a name="139" href="#139">139</a>   <em class="jxr_javadoccomment">/**</em>
<a name="140" href="#140">140</a> <em class="jxr_javadoccomment">   * Padding for Final()</em>
<a name="141" href="#141">141</a> <em class="jxr_javadoccomment">   */</em>
<a name="142" href="#142">142</a>   <strong class="jxr_keyword">static</strong> byte	padding[] = {
<a name="143" href="#143">143</a>     (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
<a name="144" href="#144">144</a>     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
<a name="145" href="#145">145</a>     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
<a name="146" href="#146">146</a>   };
<a name="147" href="#147">147</a> 
<a name="148" href="#148">148</a>   <em class="jxr_javadoccomment">/**</em>
<a name="149" href="#149">149</a> <em class="jxr_javadoccomment">   * Initialize MD5 internal state (object can be reused just by</em>
<a name="150" href="#150">150</a> <em class="jxr_javadoccomment">   * calling Init() after every Final()</em>
<a name="151" href="#151">151</a> <em class="jxr_javadoccomment">   */</em>
<a name="152" href="#152">152</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">synchronized</strong> <strong class="jxr_keyword">void</strong> Init () {
<a name="153" href="#153">153</a>     state = <strong class="jxr_keyword">new</strong> MD5State();
<a name="154" href="#154">154</a>     finals = <strong class="jxr_keyword">null</strong>;
<a name="155" href="#155">155</a>   }
<a name="156" href="#156">156</a> 
<a name="157" href="#157">157</a>   <em class="jxr_javadoccomment">/**</em>
<a name="158" href="#158">158</a> <em class="jxr_javadoccomment">   * Class constructor</em>
<a name="159" href="#159">159</a> <em class="jxr_javadoccomment">   */</em>
<a name="160" href="#160">160</a>   <strong class="jxr_keyword">public</strong> MD5 () {
<a name="161" href="#161">161</a>     <strong class="jxr_keyword">this</strong>.Init();
<a name="162" href="#162">162</a>   }
<a name="163" href="#163">163</a> 
<a name="164" href="#164">164</a>   <em class="jxr_javadoccomment">/**</em>
<a name="165" href="#165">165</a> <em class="jxr_javadoccomment">   * Initialize class, and update hash with ob.toString()</em>
<a name="166" href="#166">166</a> <em class="jxr_javadoccomment">   *</em>
<a name="167" href="#167">167</a> <em class="jxr_javadoccomment">   * @param	ob	Object, ob.toString() is used to update hash</em>
<a name="168" href="#168">168</a> <em class="jxr_javadoccomment">   *			after initialization</em>
<a name="169" href="#169">169</a> <em class="jxr_javadoccomment">   */</em>
<a name="170" href="#170">170</a>   <strong class="jxr_keyword">public</strong> MD5 (Object ob) {
<a name="171" href="#171">171</a>     <strong class="jxr_keyword">this</strong>();
<a name="172" href="#172">172</a>     Update(ob.toString());
<a name="173" href="#173">173</a>   }
<a name="174" href="#174">174</a> 
<a name="175" href="#175">175</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> rotate_left (<strong class="jxr_keyword">int</strong> x, <strong class="jxr_keyword">int</strong> n) {
<a name="176" href="#176">176</a>     <strong class="jxr_keyword">return</strong> (x &lt;&lt; n) | (x &gt;&gt;&gt; (32 - n));
<a name="177" href="#177">177</a>   }
<a name="178" href="#178">178</a> 
<a name="179" href="#179">179</a>   <em class="jxr_comment">/*<em class="jxr_comment"> I wonder how many loops and hoops you'll have to go through to</em></em>
<a name="180" href="#180">180</a> <em class="jxr_comment">     get unsigned add for longs in java */</em>
<a name="181" href="#181">181</a> 
<a name="182" href="#182">182</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> uadd (<strong class="jxr_keyword">int</strong> a, <strong class="jxr_keyword">int</strong> b) {
<a name="183" href="#183">183</a>     <strong class="jxr_keyword">long</strong> aa, bb;
<a name="184" href="#184">184</a>     aa = ((<strong class="jxr_keyword">long</strong>) a) &amp; 0xffffffffL;
<a name="185" href="#185">185</a>     bb = ((<strong class="jxr_keyword">long</strong>) b) &amp; 0xffffffffL;
<a name="186" href="#186">186</a> 
<a name="187" href="#187">187</a>     aa += bb;
<a name="188" href="#188">188</a> 
<a name="189" href="#189">189</a>     <strong class="jxr_keyword">return</strong> (<strong class="jxr_keyword">int</strong>) (aa &amp; 0xffffffffL);
<a name="190" href="#190">190</a>   }
<a name="191" href="#191">191</a> 
<a name="192" href="#192">192</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> uadd (<strong class="jxr_keyword">int</strong> a, <strong class="jxr_keyword">int</strong> b, <strong class="jxr_keyword">int</strong> c) {
<a name="193" href="#193">193</a>     <strong class="jxr_keyword">return</strong> uadd(uadd(a, b), c);
<a name="194" href="#194">194</a>   }
<a name="195" href="#195">195</a> 
<a name="196" href="#196">196</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> uadd (<strong class="jxr_keyword">int</strong> a, <strong class="jxr_keyword">int</strong> b, <strong class="jxr_keyword">int</strong> c, <strong class="jxr_keyword">int</strong> d) {
<a name="197" href="#197">197</a>     <strong class="jxr_keyword">return</strong> uadd(uadd(a, b, c), d);
<a name="198" href="#198">198</a>   }
<a name="199" href="#199">199</a> 
<a name="200" href="#200">200</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> FF (<strong class="jxr_keyword">int</strong> a, <strong class="jxr_keyword">int</strong> b, <strong class="jxr_keyword">int</strong> c, <strong class="jxr_keyword">int</strong> d, <strong class="jxr_keyword">int</strong> x, <strong class="jxr_keyword">int</strong> s, <strong class="jxr_keyword">int</strong> ac) {
<a name="201" href="#201">201</a>     a = uadd(a, ((b &amp; c) | (~b &amp; d)), x, ac);
<a name="202" href="#202">202</a>     <strong class="jxr_keyword">return</strong> uadd(rotate_left(a, s), b);
<a name="203" href="#203">203</a>   }
<a name="204" href="#204">204</a> 
<a name="205" href="#205">205</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> GG (<strong class="jxr_keyword">int</strong> a, <strong class="jxr_keyword">int</strong> b, <strong class="jxr_keyword">int</strong> c, <strong class="jxr_keyword">int</strong> d, <strong class="jxr_keyword">int</strong> x, <strong class="jxr_keyword">int</strong> s, <strong class="jxr_keyword">int</strong> ac) {
<a name="206" href="#206">206</a>     a = uadd(a, ((b &amp; d) | (c &amp; ~d)), x, ac);
<a name="207" href="#207">207</a>     <strong class="jxr_keyword">return</strong> uadd(rotate_left(a, s), b);
<a name="208" href="#208">208</a>   }
<a name="209" href="#209">209</a> 
<a name="210" href="#210">210</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> HH (<strong class="jxr_keyword">int</strong> a, <strong class="jxr_keyword">int</strong> b, <strong class="jxr_keyword">int</strong> c, <strong class="jxr_keyword">int</strong> d, <strong class="jxr_keyword">int</strong> x, <strong class="jxr_keyword">int</strong> s, <strong class="jxr_keyword">int</strong> ac) {
<a name="211" href="#211">211</a>     a = uadd(a, (b ^ c ^ d), x, ac);
<a name="212" href="#212">212</a>     <strong class="jxr_keyword">return</strong> uadd(rotate_left(a, s) , b);
<a name="213" href="#213">213</a>   }
<a name="214" href="#214">214</a> 
<a name="215" href="#215">215</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> II (<strong class="jxr_keyword">int</strong> a, <strong class="jxr_keyword">int</strong> b, <strong class="jxr_keyword">int</strong> c, <strong class="jxr_keyword">int</strong> d, <strong class="jxr_keyword">int</strong> x, <strong class="jxr_keyword">int</strong> s, <strong class="jxr_keyword">int</strong> ac) {
<a name="216" href="#216">216</a>     a = uadd(a, (c ^ (b | ~d)), x, ac);
<a name="217" href="#217">217</a>     <strong class="jxr_keyword">return</strong> uadd(rotate_left(a, s), b);
<a name="218" href="#218">218</a>   }
<a name="219" href="#219">219</a> 
<a name="220" href="#220">220</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong>[] Decode (byte buffer[], <strong class="jxr_keyword">int</strong> len, <strong class="jxr_keyword">int</strong> shift) {
<a name="221" href="#221">221</a>     <strong class="jxr_keyword">int</strong>		out[];
<a name="222" href="#222">222</a>     <strong class="jxr_keyword">int</strong> 	i, j;
<a name="223" href="#223">223</a> 
<a name="224" href="#224">224</a>     out = <strong class="jxr_keyword">new</strong> <strong class="jxr_keyword">int</strong>[16];
<a name="225" href="#225">225</a> 
<a name="226" href="#226">226</a>     <strong class="jxr_keyword">for</strong> (i = j = 0; j &lt; len; i++, j += 4) {
<a name="227" href="#227">227</a>       out[i] = ((<strong class="jxr_keyword">int</strong>) (buffer[j + shift] &amp; 0xff)) |
<a name="228" href="#228">228</a> 	(((<strong class="jxr_keyword">int</strong>) (buffer[j + 1 + shift] &amp; 0xff)) &lt;&lt; 8) |
<a name="229" href="#229">229</a> 	(((<strong class="jxr_keyword">int</strong>) (buffer[j + 2 + shift] &amp; 0xff)) &lt;&lt; 16) |
<a name="230" href="#230">230</a> 	(((<strong class="jxr_keyword">int</strong>) (buffer[j + 3 + shift] &amp; 0xff)) &lt;&lt; 24);
<a name="231" href="#231">231</a> 
<a name="232" href="#232">232</a> <em class="jxr_comment">/*<em class="jxr_comment">      System.out.println("out[" + i + "] = \t" +</em></em>
<a name="233" href="#233">233</a> <em class="jxr_comment">			 ((int) buffer[j + 0 + shift] &amp; 0xff) + "\t|\t" +</em>
<a name="234" href="#234">234</a> <em class="jxr_comment">			 ((int) buffer[j + 1 + shift] &amp; 0xff) + "\t|\t" +</em>
<a name="235" href="#235">235</a> <em class="jxr_comment">			 ((int) buffer[j + 2 + shift] &amp; 0xff) + "\t|\t" +</em>
<a name="236" href="#236">236</a> <em class="jxr_comment">			 ((int) buffer[j + 3 + shift] &amp; 0xff));*/</em>
<a name="237" href="#237">237</a>     }
<a name="238" href="#238">238</a> 
<a name="239" href="#239">239</a>     <strong class="jxr_keyword">return</strong> out;
<a name="240" href="#240">240</a>   }
<a name="241" href="#241">241</a> 
<a name="242" href="#242">242</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> Transform (MD5State state, byte buffer[], <strong class="jxr_keyword">int</strong> shift) {
<a name="243" href="#243">243</a>     <strong class="jxr_keyword">int</strong>
<a name="244" href="#244">244</a>       a = state.state[0],
<a name="245" href="#245">245</a>       b = state.state[1],
<a name="246" href="#246">246</a>       c = state.state[2],
<a name="247" href="#247">247</a>       d = state.state[3],
<a name="248" href="#248">248</a>       x[];
<a name="249" href="#249">249</a> 
<a name="250" href="#250">250</a>     x = Decode(buffer, 64, shift);
<a name="251" href="#251">251</a> 
<a name="252" href="#252">252</a>     <em class="jxr_comment">/*<em class="jxr_comment"> Round 1 */</em></em>
<a name="253" href="#253">253</a>     a = FF (a, b, c, d, x[ 0],   7, 0xd76aa478); <em class="jxr_comment">/*<em class="jxr_comment"> 1 */</em></em>
<a name="254" href="#254">254</a>     d = FF (d, a, b, c, x[ 1],  12, 0xe8c7b756); <em class="jxr_comment">/*<em class="jxr_comment"> 2 */</em></em>
<a name="255" href="#255">255</a>     c = FF (c, d, a, b, x[ 2],  17, 0x242070db); <em class="jxr_comment">/*<em class="jxr_comment"> 3 */</em></em>
<a name="256" href="#256">256</a>     b = FF (b, c, d, a, x[ 3],  22, 0xc1bdceee); <em class="jxr_comment">/*<em class="jxr_comment"> 4 */</em></em>
<a name="257" href="#257">257</a>     a = FF (a, b, c, d, x[ 4],   7, 0xf57c0faf); <em class="jxr_comment">/*<em class="jxr_comment"> 5 */</em></em>
<a name="258" href="#258">258</a>     d = FF (d, a, b, c, x[ 5],  12, 0x4787c62a); <em class="jxr_comment">/*<em class="jxr_comment"> 6 */</em></em>
<a name="259" href="#259">259</a>     c = FF (c, d, a, b, x[ 6],  17, 0xa8304613); <em class="jxr_comment">/*<em class="jxr_comment"> 7 */</em></em>
<a name="260" href="#260">260</a>     b = FF (b, c, d, a, x[ 7],  22, 0xfd469501); <em class="jxr_comment">/*<em class="jxr_comment"> 8 */</em></em>
<a name="261" href="#261">261</a>     a = FF (a, b, c, d, x[ 8],   7, 0x698098d8); <em class="jxr_comment">/*<em class="jxr_comment"> 9 */</em></em>
<a name="262" href="#262">262</a>     d = FF (d, a, b, c, x[ 9],  12, 0x8b44f7af); <em class="jxr_comment">/*<em class="jxr_comment"> 10 */</em></em>
<a name="263" href="#263">263</a>     c = FF (c, d, a, b, x[10],  17, 0xffff5bb1); <em class="jxr_comment">/*<em class="jxr_comment"> 11 */</em></em>
<a name="264" href="#264">264</a>     b = FF (b, c, d, a, x[11],  22, 0x895cd7be); <em class="jxr_comment">/*<em class="jxr_comment"> 12 */</em></em>
<a name="265" href="#265">265</a>     a = FF (a, b, c, d, x[12],   7, 0x6b901122); <em class="jxr_comment">/*<em class="jxr_comment"> 13 */</em></em>
<a name="266" href="#266">266</a>     d = FF (d, a, b, c, x[13],  12, 0xfd987193); <em class="jxr_comment">/*<em class="jxr_comment"> 14 */</em></em>
<a name="267" href="#267">267</a>     c = FF (c, d, a, b, x[14],  17, 0xa679438e); <em class="jxr_comment">/*<em class="jxr_comment"> 15 */</em></em>
<a name="268" href="#268">268</a>     b = FF (b, c, d, a, x[15],  22, 0x49b40821); <em class="jxr_comment">/*<em class="jxr_comment"> 16 */</em></em>
<a name="269" href="#269">269</a> 
<a name="270" href="#270">270</a>     <em class="jxr_comment">/*<em class="jxr_comment"> Round 2 */</em></em>
<a name="271" href="#271">271</a>     a = GG (a, b, c, d, x[ 1],   5, 0xf61e2562); <em class="jxr_comment">/*<em class="jxr_comment"> 17 */</em></em>
<a name="272" href="#272">272</a>     d = GG (d, a, b, c, x[ 6],   9, 0xc040b340); <em class="jxr_comment">/*<em class="jxr_comment"> 18 */</em></em>
<a name="273" href="#273">273</a>     c = GG (c, d, a, b, x[11],  14, 0x265e5a51); <em class="jxr_comment">/*<em class="jxr_comment"> 19 */</em></em>
<a name="274" href="#274">274</a>     b = GG (b, c, d, a, x[ 0],  20, 0xe9b6c7aa); <em class="jxr_comment">/*<em class="jxr_comment"> 20 */</em></em>
<a name="275" href="#275">275</a>     a = GG (a, b, c, d, x[ 5],   5, 0xd62f105d); <em class="jxr_comment">/*<em class="jxr_comment"> 21 */</em></em>
<a name="276" href="#276">276</a>     d = GG (d, a, b, c, x[10],   9,  0x2441453); <em class="jxr_comment">/*<em class="jxr_comment"> 22 */</em></em>
<a name="277" href="#277">277</a>     c = GG (c, d, a, b, x[15],  14, 0xd8a1e681); <em class="jxr_comment">/*<em class="jxr_comment"> 23 */</em></em>
<a name="278" href="#278">278</a>     b = GG (b, c, d, a, x[ 4],  20, 0xe7d3fbc8); <em class="jxr_comment">/*<em class="jxr_comment"> 24 */</em></em>
<a name="279" href="#279">279</a>     a = GG (a, b, c, d, x[ 9],   5, 0x21e1cde6); <em class="jxr_comment">/*<em class="jxr_comment"> 25 */</em></em>
<a name="280" href="#280">280</a>     d = GG (d, a, b, c, x[14],   9, 0xc33707d6); <em class="jxr_comment">/*<em class="jxr_comment"> 26 */</em></em>
<a name="281" href="#281">281</a>     c = GG (c, d, a, b, x[ 3],  14, 0xf4d50d87); <em class="jxr_comment">/*<em class="jxr_comment"> 27 */</em></em>
<a name="282" href="#282">282</a>     b = GG (b, c, d, a, x[ 8],  20, 0x455a14ed); <em class="jxr_comment">/*<em class="jxr_comment"> 28 */</em></em>
<a name="283" href="#283">283</a>     a = GG (a, b, c, d, x[13],   5, 0xa9e3e905); <em class="jxr_comment">/*<em class="jxr_comment"> 29 */</em></em>
<a name="284" href="#284">284</a>     d = GG (d, a, b, c, x[ 2],   9, 0xfcefa3f8); <em class="jxr_comment">/*<em class="jxr_comment"> 30 */</em></em>
<a name="285" href="#285">285</a>     c = GG (c, d, a, b, x[ 7],  14, 0x676f02d9); <em class="jxr_comment">/*<em class="jxr_comment"> 31 */</em></em>
<a name="286" href="#286">286</a>     b = GG (b, c, d, a, x[12],  20, 0x8d2a4c8a); <em class="jxr_comment">/*<em class="jxr_comment"> 32 */</em></em>
<a name="287" href="#287">287</a> 
<a name="288" href="#288">288</a>     <em class="jxr_comment">/*<em class="jxr_comment"> Round 3 */</em></em>
<a name="289" href="#289">289</a>     a = HH (a, b, c, d, x[ 5],   4, 0xfffa3942); <em class="jxr_comment">/*<em class="jxr_comment"> 33 */</em></em>
<a name="290" href="#290">290</a>     d = HH (d, a, b, c, x[ 8],  11, 0x8771f681); <em class="jxr_comment">/*<em class="jxr_comment"> 34 */</em></em>
<a name="291" href="#291">291</a>     c = HH (c, d, a, b, x[11],  16, 0x6d9d6122); <em class="jxr_comment">/*<em class="jxr_comment"> 35 */</em></em>
<a name="292" href="#292">292</a>     b = HH (b, c, d, a, x[14],  23, 0xfde5380c); <em class="jxr_comment">/*<em class="jxr_comment"> 36 */</em></em>
<a name="293" href="#293">293</a>     a = HH (a, b, c, d, x[ 1],   4, 0xa4beea44); <em class="jxr_comment">/*<em class="jxr_comment"> 37 */</em></em>
<a name="294" href="#294">294</a>     d = HH (d, a, b, c, x[ 4],  11, 0x4bdecfa9); <em class="jxr_comment">/*<em class="jxr_comment"> 38 */</em></em>
<a name="295" href="#295">295</a>     c = HH (c, d, a, b, x[ 7],  16, 0xf6bb4b60); <em class="jxr_comment">/*<em class="jxr_comment"> 39 */</em></em>
<a name="296" href="#296">296</a>     b = HH (b, c, d, a, x[10],  23, 0xbebfbc70); <em class="jxr_comment">/*<em class="jxr_comment"> 40 */</em></em>
<a name="297" href="#297">297</a>     a = HH (a, b, c, d, x[13],   4, 0x289b7ec6); <em class="jxr_comment">/*<em class="jxr_comment"> 41 */</em></em>
<a name="298" href="#298">298</a>     d = HH (d, a, b, c, x[ 0],  11, 0xeaa127fa); <em class="jxr_comment">/*<em class="jxr_comment"> 42 */</em></em>
<a name="299" href="#299">299</a>     c = HH (c, d, a, b, x[ 3],  16, 0xd4ef3085); <em class="jxr_comment">/*<em class="jxr_comment"> 43 */</em></em>
<a name="300" href="#300">300</a>     b = HH (b, c, d, a, x[ 6],  23,  0x4881d05); <em class="jxr_comment">/*<em class="jxr_comment"> 44 */</em></em>
<a name="301" href="#301">301</a>     a = HH (a, b, c, d, x[ 9],   4, 0xd9d4d039); <em class="jxr_comment">/*<em class="jxr_comment"> 45 */</em></em>
<a name="302" href="#302">302</a>     d = HH (d, a, b, c, x[12],  11, 0xe6db99e5); <em class="jxr_comment">/*<em class="jxr_comment"> 46 */</em></em>
<a name="303" href="#303">303</a>     c = HH (c, d, a, b, x[15],  16, 0x1fa27cf8); <em class="jxr_comment">/*<em class="jxr_comment"> 47 */</em></em>
<a name="304" href="#304">304</a>     b = HH (b, c, d, a, x[ 2],  23, 0xc4ac5665); <em class="jxr_comment">/*<em class="jxr_comment"> 48 */</em></em>
<a name="305" href="#305">305</a> 
<a name="306" href="#306">306</a>     <em class="jxr_comment">/*<em class="jxr_comment"> Round 4 */</em></em>
<a name="307" href="#307">307</a>     a = II (a, b, c, d, x[ 0],   6, 0xf4292244); <em class="jxr_comment">/*<em class="jxr_comment"> 49 */</em></em>
<a name="308" href="#308">308</a>     d = II (d, a, b, c, x[ 7],  10, 0x432aff97); <em class="jxr_comment">/*<em class="jxr_comment"> 50 */</em></em>
<a name="309" href="#309">309</a>     c = II (c, d, a, b, x[14],  15, 0xab9423a7); <em class="jxr_comment">/*<em class="jxr_comment"> 51 */</em></em>
<a name="310" href="#310">310</a>     b = II (b, c, d, a, x[ 5],  21, 0xfc93a039); <em class="jxr_comment">/*<em class="jxr_comment"> 52 */</em></em>
<a name="311" href="#311">311</a>     a = II (a, b, c, d, x[12],   6, 0x655b59c3); <em class="jxr_comment">/*<em class="jxr_comment"> 53 */</em></em>
<a name="312" href="#312">312</a>     d = II (d, a, b, c, x[ 3],  10, 0x8f0ccc92); <em class="jxr_comment">/*<em class="jxr_comment"> 54 */</em></em>
<a name="313" href="#313">313</a>     c = II (c, d, a, b, x[10],  15, 0xffeff47d); <em class="jxr_comment">/*<em class="jxr_comment"> 55 */</em></em>
<a name="314" href="#314">314</a>     b = II (b, c, d, a, x[ 1],  21, 0x85845dd1); <em class="jxr_comment">/*<em class="jxr_comment"> 56 */</em></em>
<a name="315" href="#315">315</a>     a = II (a, b, c, d, x[ 8],   6, 0x6fa87e4f); <em class="jxr_comment">/*<em class="jxr_comment"> 57 */</em></em>
<a name="316" href="#316">316</a>     d = II (d, a, b, c, x[15],  10, 0xfe2ce6e0); <em class="jxr_comment">/*<em class="jxr_comment"> 58 */</em></em>
<a name="317" href="#317">317</a>     c = II (c, d, a, b, x[ 6],  15, 0xa3014314); <em class="jxr_comment">/*<em class="jxr_comment"> 59 */</em></em>
<a name="318" href="#318">318</a>     b = II (b, c, d, a, x[13],  21, 0x4e0811a1); <em class="jxr_comment">/*<em class="jxr_comment"> 60 */</em></em>
<a name="319" href="#319">319</a>     a = II (a, b, c, d, x[ 4],   6, 0xf7537e82); <em class="jxr_comment">/*<em class="jxr_comment"> 61 */</em></em>
<a name="320" href="#320">320</a>     d = II (d, a, b, c, x[11],  10, 0xbd3af235); <em class="jxr_comment">/*<em class="jxr_comment"> 62 */</em></em>
<a name="321" href="#321">321</a>     c = II (c, d, a, b, x[ 2],  15, 0x2ad7d2bb); <em class="jxr_comment">/*<em class="jxr_comment"> 63 */</em></em>
<a name="322" href="#322">322</a>     b = II (b, c, d, a, x[ 9],  21, 0xeb86d391); <em class="jxr_comment">/*<em class="jxr_comment"> 64 */</em></em>
<a name="323" href="#323">323</a> 
<a name="324" href="#324">324</a>     state.state[0] += a;
<a name="325" href="#325">325</a>     state.state[1] += b;
<a name="326" href="#326">326</a>     state.state[2] += c;
<a name="327" href="#327">327</a>     state.state[3] += d;
<a name="328" href="#328">328</a>   }
<a name="329" href="#329">329</a> 
<a name="330" href="#330">330</a>   <em class="jxr_javadoccomment">/**</em>
<a name="331" href="#331">331</a> <em class="jxr_javadoccomment">   * Updates hash with the bytebuffer given (using at maximum length bytes from</em>
<a name="332" href="#332">332</a> <em class="jxr_javadoccomment">   * that buffer)</em>
<a name="333" href="#333">333</a> <em class="jxr_javadoccomment">   *</em>
<a name="334" href="#334">334</a> <em class="jxr_javadoccomment">   * @param state	Which state is updated</em>
<a name="335" href="#335">335</a> <em class="jxr_javadoccomment">   * @param buffer	Array of bytes to be hashed</em>
<a name="336" href="#336">336</a> <em class="jxr_javadoccomment">   * @param offset	Offset to buffer array</em>
<a name="337" href="#337">337</a> <em class="jxr_javadoccomment">   * @param length	Use at maximum `length' bytes (absolute</em>
<a name="338" href="#338">338</a> <em class="jxr_javadoccomment">   *			maximum is buffer.length)</em>
<a name="339" href="#339">339</a> <em class="jxr_javadoccomment">   */</em>
<a name="340" href="#340">340</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> Update (MD5State stat, byte buffer[], <strong class="jxr_keyword">int</strong> offset, <strong class="jxr_keyword">int</strong> length) {
<a name="341" href="#341">341</a>     <strong class="jxr_keyword">int</strong>	index, partlen, i, start;
<a name="342" href="#342">342</a> 
<a name="343" href="#343">343</a> <em class="jxr_comment">/*<em class="jxr_comment">    System.out.print("Offset = " + offset + "\tLength = " + length + "\t");</em></em>
<a name="344" href="#344">344</a> <em class="jxr_comment">    System.out.print("Buffer = ");</em>
<a name="345" href="#345">345</a> <em class="jxr_comment">    for (i = 0; i &lt; buffer.length; i++)</em>
<a name="346" href="#346">346</a> <em class="jxr_comment">	System.out.print((int) (buffer[i] &amp; 0xff) + " ");</em>
<a name="347" href="#347">347</a> <em class="jxr_comment">    System.out.print("\n");*/</em>
<a name="348" href="#348">348</a> 
<a name="349" href="#349">349</a>     finals = <strong class="jxr_keyword">null</strong>;
<a name="350" href="#350">350</a> 
<a name="351" href="#351">351</a>     <em class="jxr_comment">/*<em class="jxr_comment"> Length can be told to be shorter, but not inter */</em></em>
<a name="352" href="#352">352</a>     <strong class="jxr_keyword">if</strong> ((length - offset)&gt; buffer.length)
<a name="353" href="#353">353</a>       length = buffer.length - offset;
<a name="354" href="#354">354</a> 
<a name="355" href="#355">355</a>     <em class="jxr_comment">/*<em class="jxr_comment"> compute number of bytes mod 64 */</em></em>
<a name="356" href="#356">356</a>     index = (<strong class="jxr_keyword">int</strong>) (stat.count[0] &gt;&gt;&gt; 3) &amp; 0x3f;
<a name="357" href="#357">357</a> 
<a name="358" href="#358">358</a>     <strong class="jxr_keyword">if</strong> ((stat.count[0] += (length &lt;&lt; 3)) &lt;
<a name="359" href="#359">359</a> 	(length &lt;&lt; 3))
<a name="360" href="#360">360</a>       stat.count[1]++;
<a name="361" href="#361">361</a> 
<a name="362" href="#362">362</a>     stat.count[1] += length &gt;&gt;&gt; 29;
<a name="363" href="#363">363</a> 
<a name="364" href="#364">364</a>     partlen = 64 - index;
<a name="365" href="#365">365</a> 
<a name="366" href="#366">366</a>     <strong class="jxr_keyword">if</strong> (length &gt;= partlen) {
<a name="367" href="#367">367</a>       <strong class="jxr_keyword">for</strong> (i = 0; i &lt; partlen; i++)
<a name="368" href="#368">368</a> 	stat.buffer[i + index] = buffer[i + offset];
<a name="369" href="#369">369</a> 
<a name="370" href="#370">370</a>       Transform(stat, stat.buffer, 0);
<a name="371" href="#371">371</a> 
<a name="372" href="#372">372</a>       <strong class="jxr_keyword">for</strong> (i = partlen; (i + 63) &lt; length; i+= 64)
<a name="373" href="#373">373</a> 	Transform(stat, buffer, i);
<a name="374" href="#374">374</a> 
<a name="375" href="#375">375</a>       index = 0;
<a name="376" href="#376">376</a>     } <strong class="jxr_keyword">else</strong>
<a name="377" href="#377">377</a>       i = 0;
<a name="378" href="#378">378</a> 
<a name="379" href="#379">379</a>     <em class="jxr_comment">/*<em class="jxr_comment"> buffer remaining input */</em></em>
<a name="380" href="#380">380</a>     <strong class="jxr_keyword">if</strong> (i &lt; length) {
<a name="381" href="#381">381</a>       start = i;
<a name="382" href="#382">382</a>       <strong class="jxr_keyword">for</strong> (; i &lt; length; i++)
<a name="383" href="#383">383</a> 	stat.buffer[index + i - start] = buffer[i + offset];
<a name="384" href="#384">384</a>     }
<a name="385" href="#385">385</a>   }
<a name="386" href="#386">386</a> 
<a name="387" href="#387">387</a>   <em class="jxr_comment">/*</em>
<a name="388" href="#388">388</a> <em class="jxr_comment">   * Update()s for other datatypes than byte[] also. Update(byte[], int)</em>
<a name="389" href="#389">389</a> <em class="jxr_comment">   * is only the main driver.</em>
<a name="390" href="#390">390</a> <em class="jxr_comment">   */</em>
<a name="391" href="#391">391</a> 
<a name="392" href="#392">392</a>   <em class="jxr_javadoccomment">/**</em>
<a name="393" href="#393">393</a> <em class="jxr_javadoccomment">   * Plain update, updates this object</em>
<a name="394" href="#394">394</a> <em class="jxr_javadoccomment">   */</em>
<a name="395" href="#395">395</a> 
<a name="396" href="#396">396</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> Update (byte buffer[], <strong class="jxr_keyword">int</strong> offset, <strong class="jxr_keyword">int</strong> length) {
<a name="397" href="#397">397</a>       Update(<strong class="jxr_keyword">this</strong>.state, buffer, offset, length);
<a name="398" href="#398">398</a>   }
<a name="399" href="#399">399</a> 
<a name="400" href="#400">400</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> Update (byte buffer[], <strong class="jxr_keyword">int</strong> length) {
<a name="401" href="#401">401</a>       Update(<strong class="jxr_keyword">this</strong>.state, buffer, 0, length);
<a name="402" href="#402">402</a>   }
<a name="403" href="#403">403</a> 
<a name="404" href="#404">404</a>   <em class="jxr_javadoccomment">/**</em>
<a name="405" href="#405">405</a> <em class="jxr_javadoccomment">   * Updates hash with given array of bytes</em>
<a name="406" href="#406">406</a> <em class="jxr_javadoccomment">   *</em>
<a name="407" href="#407">407</a> <em class="jxr_javadoccomment">   * @param buffer	Array of bytes to use for updating the hash</em>
<a name="408" href="#408">408</a> <em class="jxr_javadoccomment">   */</em>
<a name="409" href="#409">409</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> Update (byte buffer[]) {
<a name="410" href="#410">410</a>       Update(buffer, 0, buffer.length);
<a name="411" href="#411">411</a>   }
<a name="412" href="#412">412</a> 
<a name="413" href="#413">413</a>   <em class="jxr_javadoccomment">/**</em>
<a name="414" href="#414">414</a> <em class="jxr_javadoccomment">   * Updates hash with a single byte</em>
<a name="415" href="#415">415</a> <em class="jxr_javadoccomment">   *</em>
<a name="416" href="#416">416</a> <em class="jxr_javadoccomment">   * @param b		Single byte to update the hash</em>
<a name="417" href="#417">417</a> <em class="jxr_javadoccomment">   */</em>
<a name="418" href="#418">418</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> Update (byte b) {
<a name="419" href="#419">419</a>     byte buffer[] = <strong class="jxr_keyword">new</strong> byte[1];
<a name="420" href="#420">420</a>     buffer[0] = b;
<a name="421" href="#421">421</a> 
<a name="422" href="#422">422</a>     Update(buffer, 1);
<a name="423" href="#423">423</a>   }
<a name="424" href="#424">424</a> 
<a name="425" href="#425">425</a>   <em class="jxr_javadoccomment">/**</em>
<a name="426" href="#426">426</a> <em class="jxr_javadoccomment">   * Update buffer with given string.</em>
<a name="427" href="#427">427</a> <em class="jxr_javadoccomment">   *</em>
<a name="428" href="#428">428</a> <em class="jxr_javadoccomment">   * @param s		String to be update to hash (is used as</em>
<a name="429" href="#429">429</a> <em class="jxr_javadoccomment">   *		       	s.getBytes())</em>
<a name="430" href="#430">430</a> <em class="jxr_javadoccomment">   */</em>
<a name="431" href="#431">431</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> Update (String s) {
<a name="432" href="#432">432</a>     byte	chars[];
<a name="433" href="#433">433</a> 
<a name="434" href="#434">434</a> <em class="jxr_comment">//     chars = new byte[s.length()];</em>
<a name="435" href="#435">435</a> <em class="jxr_comment">//     s.getBytes(0, s.length(), chars, 0);</em>
<a name="436" href="#436">436</a>     
<a name="437" href="#437">437</a> 	chars = StringUtil.toUtf8ByteArray(s);
<a name="438" href="#438">438</a>     
<a name="439" href="#439">439</a> 
<a name="440" href="#440">440</a>     Update(chars, chars.length);
<a name="441" href="#441">441</a>   }
<a name="442" href="#442">442</a> 
<a name="443" href="#443">443</a>   <em class="jxr_javadoccomment">/**</em>
<a name="444" href="#444">444</a> <em class="jxr_javadoccomment">   * Update buffer with a single integer (only &amp; 0xff part is used,</em>
<a name="445" href="#445">445</a> <em class="jxr_javadoccomment">   * as a byte)</em>
<a name="446" href="#446">446</a> <em class="jxr_javadoccomment">   *</em>
<a name="447" href="#447">447</a> <em class="jxr_javadoccomment">   * @param i		Integer value, which is then converted to</em>
<a name="448" href="#448">448</a> <em class="jxr_javadoccomment">   *			byte as i &amp; 0xff</em>
<a name="449" href="#449">449</a> <em class="jxr_javadoccomment">   */</em>
<a name="450" href="#450">450</a> 
<a name="451" href="#451">451</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> Update (<strong class="jxr_keyword">int</strong> i) {
<a name="452" href="#452">452</a>       Update((byte) (i &amp; 0xff));
<a name="453" href="#453">453</a>   }
<a name="454" href="#454">454</a> 
<a name="455" href="#455">455</a>   <strong class="jxr_keyword">private</strong> byte[] Encode (<strong class="jxr_keyword">int</strong> input[], <strong class="jxr_keyword">int</strong> len) {
<a name="456" href="#456">456</a>     <strong class="jxr_keyword">int</strong>		i, j;
<a name="457" href="#457">457</a>     byte	out[];
<a name="458" href="#458">458</a> 
<a name="459" href="#459">459</a>     out = <strong class="jxr_keyword">new</strong> byte[len];
<a name="460" href="#460">460</a> 
<a name="461" href="#461">461</a>     <strong class="jxr_keyword">for</strong> (i = j = 0; j  &lt; len; i++, j += 4) {
<a name="462" href="#462">462</a>       out[j] = (byte) (input[i] &amp; 0xff);
<a name="463" href="#463">463</a>       out[j + 1] = (byte) ((input[i] &gt;&gt;&gt; 8) &amp; 0xff);
<a name="464" href="#464">464</a>       out[j + 2] = (byte) ((input[i] &gt;&gt;&gt; 16) &amp; 0xff);
<a name="465" href="#465">465</a>       out[j + 3] = (byte) ((input[i] &gt;&gt;&gt; 24) &amp; 0xff);
<a name="466" href="#466">466</a>     }
<a name="467" href="#467">467</a> 
<a name="468" href="#468">468</a>     <strong class="jxr_keyword">return</strong> out;
<a name="469" href="#469">469</a>   }
<a name="470" href="#470">470</a> 
<a name="471" href="#471">471</a>   <em class="jxr_javadoccomment">/**</em>
<a name="472" href="#472">472</a> <em class="jxr_javadoccomment">   * Returns array of bytes (16 bytes) representing hash as of the</em>
<a name="473" href="#473">473</a> <em class="jxr_javadoccomment">   * current state of this object. Note: getting a hash does not</em>
<a name="474" href="#474">474</a> <em class="jxr_javadoccomment">   * invalidate the hash object, it only creates a copy of the real</em>
<a name="475" href="#475">475</a> <em class="jxr_javadoccomment">   * state which is finalized.</em>
<a name="476" href="#476">476</a> <em class="jxr_javadoccomment">   *</em>
<a name="477" href="#477">477</a> <em class="jxr_javadoccomment">   * @return	Array of 16 bytes, the hash of all updated bytes</em>
<a name="478" href="#478">478</a> <em class="jxr_javadoccomment">   */</em>
<a name="479" href="#479">479</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">synchronized</strong> byte[] Final () {
<a name="480" href="#480">480</a>     byte	bits[];
<a name="481" href="#481">481</a>     <strong class="jxr_keyword">int</strong>		index, padlen;
<a name="482" href="#482">482</a>     MD5State	fin;
<a name="483" href="#483">483</a> 
<a name="484" href="#484">484</a>     <strong class="jxr_keyword">if</strong> (finals == <strong class="jxr_keyword">null</strong>) {
<a name="485" href="#485">485</a>       fin = <strong class="jxr_keyword">new</strong> MD5State(state);
<a name="486" href="#486">486</a> 
<a name="487" href="#487">487</a>       bits = Encode(fin.count, 8);
<a name="488" href="#488">488</a> 
<a name="489" href="#489">489</a>       index = (<strong class="jxr_keyword">int</strong>) ((fin.count[0] &gt;&gt;&gt; 3) &amp; 0x3f);
<a name="490" href="#490">490</a>       padlen = (index &lt; 56) ? (56 - index) : (120 - index);
<a name="491" href="#491">491</a> 
<a name="492" href="#492">492</a>       Update(fin, padding, 0, padlen);
<a name="493" href="#493">493</a>       <em class="jxr_javadoccomment">/**</em><em class="jxr_javadoccomment">/</em>
<a name="494" href="#494">494</a> <em class="jxr_javadoccomment">      Update(fin, bits, 0, 8);</em>
<a name="495" href="#495">495</a> 
<a name="496" href="#496">496</a> <em class="jxr_javadoccomment">      /* Update() sets finalds to null */</em>
<a name="497" href="#497">497</a>       finals = fin;
<a name="498" href="#498">498</a>     }
<a name="499" href="#499">499</a> 
<a name="500" href="#500">500</a>     <strong class="jxr_keyword">return</strong> Encode(finals.state, 16);
<a name="501" href="#501">501</a>   }
<a name="502" href="#502">502</a> 
<a name="503" href="#503">503</a>   <em class="jxr_javadoccomment">/**</em>
<a name="504" href="#504">504</a> <em class="jxr_javadoccomment">   * Turns array of bytes into string representing each byte as</em>
<a name="505" href="#505">505</a> <em class="jxr_javadoccomment">   * unsigned hex number.</em>
<a name="506" href="#506">506</a> <em class="jxr_javadoccomment">   *</em>
<a name="507" href="#507">507</a> <em class="jxr_javadoccomment">   * @param hash	Array of bytes to convert to hex-string</em>
<a name="508" href="#508">508</a> <em class="jxr_javadoccomment">   * @return	Generated hex string</em>
<a name="509" href="#509">509</a> <em class="jxr_javadoccomment">   */</em>
<a name="510" href="#510">510</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> String asHex (byte hash[]) {
<a name="511" href="#511">511</a>     StringBuffer buf = <strong class="jxr_keyword">new</strong> StringBuffer(hash.length * 2);
<a name="512" href="#512">512</a>     <strong class="jxr_keyword">int</strong> i;
<a name="513" href="#513">513</a> 
<a name="514" href="#514">514</a>     <strong class="jxr_keyword">for</strong> (i = 0; i &lt; hash.length; i++) {
<a name="515" href="#515">515</a>       <strong class="jxr_keyword">if</strong> (((<strong class="jxr_keyword">int</strong>) hash[i] &amp; 0xff) &lt; 0x10)
<a name="516" href="#516">516</a> 	buf.append(<span class="jxr_string">"0"</span>);
<a name="517" href="#517">517</a> 
<a name="518" href="#518">518</a>       buf.append(Long.toString((<strong class="jxr_keyword">int</strong>) hash[i] &amp; 0xff, 16));
<a name="519" href="#519">519</a>     }
<a name="520" href="#520">520</a> 
<a name="521" href="#521">521</a>     <strong class="jxr_keyword">return</strong> buf.toString();
<a name="522" href="#522">522</a>   }
<a name="523" href="#523">523</a> 
<a name="524" href="#524">524</a>   <em class="jxr_javadoccomment">/**</em>
<a name="525" href="#525">525</a> <em class="jxr_javadoccomment">   * Returns 32-character hex representation of this objects hash</em>
<a name="526" href="#526">526</a> <em class="jxr_javadoccomment">   *</em>
<a name="527" href="#527">527</a> <em class="jxr_javadoccomment">   * @return String of this object's hash</em>
<a name="528" href="#528">528</a> <em class="jxr_javadoccomment">   */</em>
<a name="529" href="#529">529</a>   <strong class="jxr_keyword">public</strong> String asHex () {
<a name="530" href="#530">530</a>     <strong class="jxr_keyword">return</strong> asHex(<strong class="jxr_keyword">this</strong>.Final());
<a name="531" href="#531">531</a>   }
<a name="532" href="#532">532</a> }
</pre>
<hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body>
</html>

